class UsersController < ApplicationController
  
  sidebar :deposits, :if => :logged_in?
  sidebar :ajax_module_balans, :if => :logged_in?
  
  skip_before_filter :login_required, :only => [:display_login_fields]
  
  # render new.rhtml
  def new
  end

  def create
    cookies.delete :auth_token
    # protects against session fixation attacks, wreaks havoc with 
    # request forgery protection.
    # uncomment at your own risk
    # reset_session
    @user = User.new(params[:user])

    @user.save!
    self.current_user = @user
    redirect_back_or_default('/')
    flash[:notice] = "Thanks for signing up!"
  rescue ActiveRecord::RecordInvalid
    render :action => 'new'
  end
  
  def update
    #Must be find_by_id and not find()
    @user= User.find_by_id(params[:id])
    @user.attributes = params[:user]
    
    if @user.save
      flash[:message] = 'Profiel opgeslagen'
      return redirect_to(my_profile_url)
    else
      flash[:error] = 'Er ging iets mis met het opslaan van je profiel!'
      render :action => 'edit'
    end
  end
  
  def display_login_fields
    #Get all users to show
    @users = User.get_all_active
    @id = params[:id]
  end
  
  def edit_current_user
    @user = current_user
    edit
  end
  
private

  def edit
    render :action => 'edit'
  end
  

end
